package edu.gdkm.service.impl;

import edu.gdkm.dao.IBookDao;
import edu.gdkm.dao.IRecordDao;
import edu.gdkm.dao.IStudentDao;
import edu.gdkm.pojo.Book;
import edu.gdkm.pojo.Record;
import edu.gdkm.pojo.Student;
import edu.gdkm.service.IRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
@Service
public class RecordServiceImpl implements IRecordService {
    @Autowired
    IRecordDao iRecordDao;
    @Autowired
    IStudentDao iStudentDao;
    @Autowired
    IBookDao iBookDao;
    @Override
    public boolean borrowBook(Student student, Book book) {
        Record record=new Record();
        record.setSid(student.getSid());
        record.setBid(book.getBid());
        record.setBorrowtime(new Date());
        iRecordDao.insertRecord(record);
        student.setBorrowCount(student.getBorrowCount()+1);
        iStudentDao.updateStudent(student);
        book.setBtype(1);
        iBookDao.updateBook(book);
        return record.getRid()!=null;
    }
}
